﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using System.Text;
using System.Xml;


public partial class allergy_getKewords : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //XmlElement work = doc.CreateElement("work");
        //string time = row["creatTime"].ToString().Trim();
        //work.SetAttribute("id", row["id"].ToString());
        //work.SetAttribute("title", row["title"].ToString());
        //work.SetAttribute("author", row["author"].ToString());
        //work.SetAttribute("pic", row["pic"].ToString());
        //work.SetAttribute("date", time.Substring(0, time.Length - (time.LastIndexOf(" "))).Replace("-", "."));
        //data.AppendChild(work);

        DataTable dt = BLLArticleInfo.getKeywords();
        string a = dt.Rows[0]["num"].ToString();
        //生成xml文档
        Response.Clear();
        Encoding gb2312 = Encoding.GetEncoding("UTF-8");
        Response.ContentEncoding = gb2312;
        XmlDocument doc = new XmlDocument();
        XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
        doc.AppendChild(decl);

        //创建根节点   data
        XmlElement data = doc.CreateElement("data");
        doc.AppendChild(data);

        XmlElement keyword1 = doc.CreateElement("keyword");
        keyword1.SetAttribute("size", "1");
        keyword1.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[0]["keword"].ToString()));
        keyword1.SetAttribute("name", dt.Rows[0]["keword"].ToString());
        data.AppendChild(keyword1);

        XmlElement keyword2 = doc.CreateElement("keyword");
        keyword2.SetAttribute("size", "2");
        keyword2.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[1]["keword"].ToString()));
        keyword2.SetAttribute("name", dt.Rows[1]["keword"].ToString());
        data.AppendChild(keyword2);

        XmlElement keyword3 = doc.CreateElement("keyword");
        keyword3.SetAttribute("size", "2");
        keyword3.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[2]["keword"].ToString()));
        keyword3.SetAttribute("name", dt.Rows[2]["keword"].ToString());
        data.AppendChild(keyword3);

        XmlElement keyword4 = doc.CreateElement("keyword");
        keyword4.SetAttribute("size", "2");
        keyword4.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[3]["keword"].ToString()));
        keyword4.SetAttribute("name", dt.Rows[3]["keword"].ToString());
        data.AppendChild(keyword4);

        XmlElement keyword5 = doc.CreateElement("keyword");
        keyword5.SetAttribute("size", "3");
        keyword5.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[4]["keword"].ToString()));
        keyword5.SetAttribute("name", dt.Rows[4]["keword"].ToString());
        data.AppendChild(keyword5);

        XmlElement keyword6 = doc.CreateElement("keyword");
        keyword6.SetAttribute("size", "3");
        keyword6.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[5]["keword"].ToString()));
        keyword6.SetAttribute("name", dt.Rows[5]["keword"].ToString());
        data.AppendChild(keyword6);

        XmlElement keyword7 = doc.CreateElement("keyword");
        keyword7.SetAttribute("size", "3");
        keyword7.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[6]["keword"].ToString()));
        keyword7.SetAttribute("name", dt.Rows[6]["keword"].ToString());
        data.AppendChild(keyword7);

        XmlElement keyword8 = doc.CreateElement("keyword");
        keyword8.SetAttribute("size", "3");
        keyword8.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[7]["keword"].ToString()));
        keyword8.SetAttribute("name", dt.Rows[7]["keword"].ToString());
        data.AppendChild(keyword8);

        XmlElement keyword9 = doc.CreateElement("keyword");
        keyword9.SetAttribute("size", "4");
        keyword9.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[8]["keword"].ToString()));
        keyword9.SetAttribute("name", dt.Rows[8]["keword"].ToString());
        data.AppendChild(keyword9);

        XmlElement keyword10 = doc.CreateElement("keyword");
        keyword10.SetAttribute("size", "4");
        keyword10.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[9]["keword"].ToString()));
        keyword10.SetAttribute("name", dt.Rows[9]["keword"].ToString());
        data.AppendChild(keyword10);

        XmlElement keyword11 = doc.CreateElement("keyword");
        keyword11.SetAttribute("size", "4");
        keyword11.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[10]["keword"].ToString()));
        keyword11.SetAttribute("name", dt.Rows[10]["keword"].ToString());
        data.AppendChild(keyword11);

        XmlElement keyword12 = doc.CreateElement("keyword");
        keyword12.SetAttribute("size", "4");
        keyword12.SetAttribute("url", "search/search.aspx?key=" + Server.UrlEncode(dt.Rows[11]["keword"].ToString()));
        keyword12.SetAttribute("name", dt.Rows[11]["keword"].ToString());
        data.AppendChild(keyword12);
 
        //向页面输出xml文档
        Response.Write(doc.OuterXml);
        Response.End();

    }
}
